package com.credithc.customers.manager.schedule;

import com.credithc.customers.base.factory.DictionaryFactory;
import com.credithc.customers.manager.service.ScheduleService;
import com.credithc.customers.manager.utils.StatsUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * @author zhukai
 * @date 2019/1/4 9:42
 */
//@Component
@Slf4j
public class ScheduleTask {


    private final ScheduleService scheduleService;

    @Autowired
    public ScheduleTask(ScheduleService scheduleService) {
        this.scheduleService = scheduleService;
    }


//    @Scheduled(cron = "0 0 0 * * ?")
//    @Async("myTaskAsyncPool")
    public void statsCustomer() {
        String currentDay = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        currentDay = StatsUtils.getPastDate(1, currentDay);
        scheduleService.statsCustomerCount(currentDay);
    }

//    @Scheduled(cron = "0 30 0 * * ?")
//    @Async("myTaskAsyncPool")
    public void statsPreChange() {
        String currentDay = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        currentDay = StatsUtils.getPastDate(1, currentDay);
        scheduleService.statsPreChange(currentDay);
    }

    //@Scheduled(cron = "0 00 10 * * ?")
    public void editAbnormalAndEmail() {
        if (DictionaryFactory.SysSettings.enabledTask()) {
            scheduleService.editAbnormalAndEmail();
        }
    }
}
